﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Modeling.Diagrams;

namespace Demo.AgilePlanner
{
    public partial class BaseSwimLane
    {
        public override BoundsRules BoundsRules
        {
            get
            {
                return new MySwimLaneBoundRules();
            }
        }

        //internal void UpdateStoryContainerCapacity()
        //{
        //    StoryContainer storyContainer = ModelElement as StoryContainer;
        //    if (storyContainer != null)
        //    {
        //        Store.TransactionManager.BeginTransaction();
        //        //storyContainer.UpdateCapacity();
        //        Store.TransactionManager.CurrentTransaction.Commit();
        //    }
        //}
    }

    public class MySwimLaneBoundRules : BoundsRules
    {
        public override RectangleD GetCompliantBounds(ShapeElement shape, RectangleD proposedBounds)
        {
            double maxWidth = shape.DefaultSize.Width;
            if (shape.HasChildren)
            {
                double rightExtend = 0;
                foreach (ShapeElement se in shape.NestedChildShapes)
                {
                    if (se.AbsoluteBoundingBox.Right > rightExtend)
                    {
                        rightExtend = se.AbsoluteBoundingBox.Right;
                    }
                }
                maxWidth = rightExtend - shape.AbsoluteBoundingBox.Left + 0.5; //padding;
            }

            if (proposedBounds.Width > maxWidth)
            {
                proposedBounds.Width = maxWidth;
            }
            return proposedBounds;
        }
    }



}
